<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    var options = {
      timeout: 5000,
      enableHeightAccuracy: true,
    };

    // 判断当前浏览器是否支持定位
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(success, error, options);
    } else {
      console.log("您的浏览器不支持定位");
    }

    function success(info) {
      console.log(info); //谷歌可以定位但不能获取地理位置值
      console.log(info.coords);
      console.log(info.coords.latitude); //维度
      console.log(info.coords.longitude); //经度
    }

    function error(err) {
      console.log(err);
    }
  </script>
</html>
